﻿using System.Linq;
using System.Web.Services;
using System.Collections.Generic;
using CounterServerModel;
using CounterServerModel.Authentication;

namespace SmartCounters.WebServices
{
    /// <summary>
    /// This is a Web Service that represents Billing Service in the model of the system.
    /// </summary>
    [WebService(Namespace = "http://smartcounters.org")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class BillingWebService : WebService
    {
        [WebMethod]
        public double GetMonthlyUsageSoFar(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, int i_AccountID)
        {
            return new BillingService().GetMonthlyUsageSoFar(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_AccountID);
        }

        [WebMethod]
        public SingleUsage[] GetUsagePredictionForOneMonth(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, int i_AccountID)
        {
            return new BillingService().GetUsagePredictionForOneMonth(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_AccountID).Usages.Values.ToArray();
        }

        [WebMethod]
        public Bill CreateBill(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, int i_AccountID, int i_Year, int i_Month)
        {
            return new BillingService().CreateBill(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_AccountID, i_Year, i_Month);
        }

        [WebMethod]
        public Bill GetBillPrediction(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, int i_AccountID, int i_Year, int i_Month)
        {
            return new BillingService().GetBillPrediction(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_AccountID, i_Year, i_Month);
        }

        [WebMethod]
        public Bill GetBill(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, int i_AccountID, int i_Year, int i_Month, bool i_SendBillByEmail)
        {
            return new BillingService().GetBill(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_AccountID, i_Year, i_Month, i_SendBillByEmail);
        }

        [WebMethod]
        public BillingInfo GetCurrentPrice(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword)
        {
            return new BillingService().GetCurrentPrice(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword));
        }

        [WebMethod]
        public void SetCurrentPrice(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword, double i_PriceForLiter, string i_Comments)
        {
            new BillingService().SetCurrentPrice(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword), i_PriceForLiter, i_Comments);
        }

        [WebMethod]
        public bool IsPriceSet(int i_AuthenticatedUserID, string i_AuthenticatedUserPassword)
        {
            return new BillingService().IsPriceSet(new AuthenticatedUserCredentials(i_AuthenticatedUserID, i_AuthenticatedUserPassword));
        }
    }
}
